﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using emp.SqlServerDAL;

public partial class crm_salienceMember_UploadPage : System.Web.UI.Page
{
    private DataTable getTableInfo(string sql)
    {
        DataSet data = new DataSet();
        using (SqlDataAdapter sda = new SqlDataAdapter())
        {
            try
            {
                sda.SelectCommand = new SqlCommand();
                sda.SelectCommand.CommandText = sql;
                sda.SelectCommand.Connection = new SqlConnection(SQLHelper.CONN_STRING_NON_DTC);
                sda.Fill(data);
            }
            catch { }
        }
        return data.Tables[0];
    }


    protected void Page_Load(object sender, EventArgs e)
    {
         
        if (!this.IsPostBack)
        {
            string filename = "";
            if (!string.IsNullOrEmpty(Request.Params["TCB_ID"]))
            {
                string sql = "SELECT  TCB_ID      ,TCB_XLS_FILE      ,TCB_STATUS      ,TCB_VALID_NUM      ,TCB_DOLOAD_USER      ,convert(varchar, TCB_DOLOAD_DATE,111) as TCB_DOLOAD_DATE      ,TCB_REMARK  FROM TASTE_CAR_BATCH  WHERE TCB_ID='" + Request.Params["TCB_ID"] .ToString()+ "'";
                DataTable dt = getTableInfo(sql);

                if (dt.Rows.Count>0)
                {
                    filename = dt.Rows[0]["TCB_XLS_FILE"].ToString();
                    string path = HttpContext.Current.Server.MapPath("excel/") + filename;
                    
                    System.IO.FileInfo fileInfo = new System.IO.FileInfo(path);
                    if (fileInfo.Exists == false)
                    {
                        Response.Write("<script>alert('下载文件数据为空!');</script>");
                        Response.Write("<script language=javascript>window.history.go(-1);</script>");
                        return;
                    }
                    Response.Clear();
                    Response.ContentType = "application/x-excel";
                    Response.AddHeader("Content-Disposition", "attachment;FileName=" + HttpUtility.UrlEncode(filename, System.Text.Encoding.UTF8));
                    Response.WriteFile(path);


                }

               
                
            }
           

            
            Response.End();
        }
    }
}
